#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/wait.h>
#include <stdlib.h>


int main()
{
  printf("firstttttttttttttttt\n");
  char buf[100]={0};
  pid_t cld_pid;
  int fd;
  int status;
  if((fd=open("temp",O_CREAT|O_RDWR|O_TRUNC,0664))==-1){

  perror("createfile");	
	exit(1);
	}
 printf("ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh,%d\n",getpid());
 strcpy(buf,"parentProcess Data");
  if((cld_pid=fork())==0){
    printf("cld_pid is %d\n",cld_pid);
  	strcpy(buf,"subprocess data");
  	puts("subProcess is working");
  	printf("sub Pid is %d\n",getpid());
  	printf("pPad is %d\n",getppid());
  	write(fd,buf,strlen(buf));
  	close(fd);
  	puts("sub proces is byby");
  	exit(0);

  }else{
  	    printf("cld_pid is %d\n",cld_pid);
  	puts("PPproces is working");
  	printf("PPid is %d\n",getpid());
  	printf("sub pid is %d\n",cld_pid);

  	write(fd,buf,strlen(buf));
    puts("ppid is byby");
  	close(fd);
  }
 // wait(&status);


	return 0;
}